package com.example.mobile2021606170hsy0330homework;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private EditText edtTxtMainName;
    private EditText edtTxtMainPsw;
    private Button btnMainLogin;
    private Button btMainReset;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btnMainLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //获取输入内容
                String name = edtTxtMainName.getText().toString();
                String password = edtTxtMainPsw.getText().toString();
                //输入不完整的判断
                if (name.length() == 0) {
                    Log.i("登录", "请输入用户名 ");

                } else if (password.length() == 0) {
                    Log.i("登录", "请输入密码 ");
                } else {
                }
                //判断
                if (name.equals("admin") & password.equals("12456")) {
                    Log.d("登录", "登录成功 ");
                } else {
                    Log.i("登录", "登录失败");
                }
                edtTxtMainName.setText(null);
                edtTxtMainPsw.setText(null);
            }

        });

        //点击“重置”按钮时，两个输入框内容清空。
      btMainReset.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              edtTxtMainName.setText(null);
              edtTxtMainPsw.setText(null);
          }
      });
    }
    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        edtTxtMainName = (EditText) findViewById(R.id.edtTxt_main_name);
        edtTxtMainPsw = (EditText) findViewById(R.id.edtTxt_main_psw);
        btnMainLogin = (Button) findViewById(R.id.btn_main_login);
        btMainReset = (Button) findViewById(R.id.bt_main_reset);
    }
}